﻿using Domain.Events;
using Domain.ValueObjects;
using Shared.Domain.Abstructs;
using Shared.Domain.Interface;

namespace Domain.Entities
{
    /// <summary>
    /// 用户行为管理
    /// </summary>
    public partial class User : BaseEntity<Guid>, IAggregateRoot
    {
        /// <summary>
        /// 修改手机号
        /// </summary>
        /// <param name="newPhoneNumber"></param>
        public void ChangePhoneNumber(PhoneNumber newPhoneNumber)
        {
            var oldNumber = this.PhoneNumber;
            PhoneNumber = newPhoneNumber;
            //发布事件
            events.Add(new UserPhoneNumberUpdated(Id, oldNumber, this.PhoneNumber));
        }

        /// <summary>
        /// 修改用户名
        /// </summary>
        /// <param name="newUserName"></param>
        public void ChangeUserName(NickName newUserName)
        {
            var oldName = this.NickName;
            NickName = newUserName;
            events.Add(new UserNameUpdated(Id, oldName, this.NickName));
        }


        private void ChangePassword(string newPlainPassword)
        {
            PasswordHash = newPlainPassword;
            events.Add(new UserPasswordUpdated(Id));
        }

        public void ChangeAcademicInfo(AcademicInfo newAcademicInfo)
        {
            var oldInfo = this.AcademicInfo;
            AcademicInfo = newAcademicInfo;
            events.Add(new UserAcademicInfoUpdated(Id, oldInfo, this.AcademicInfo));
        }

        public void Delete()
        {
            IsDeleted = true;
            //添加事件
        }
        
    }
}
